﻿CREATE FUNCTION dbo.fs_MenuPages_OLD
( @MenuID int,
	@FramePage bit
)
RETURNS @Ret TABLE (PageID int, PageDesc nvarchar(128),PageUrl varchar(256),ParentMenuID int,TabIndex int)
AS BEGIN

DECLARE @T TABLE (PageID int, PageDesc nvarchar(128),PageUrl varchar(256),ParentMenuID int,TabIndex int)
DECLARE @PageTypeID int


INSERT INTO @T
SELECT PageID, PageDesc, PageURL,ParentMenuID,TabIndex
FROM  v_Menu_Pages_NameSpace
WHERE (MenuID = @MenuID) AND
			((@FramePage = 1 AND PageTypeID = 9) OR
			 (@FramePage = 0 AND ISNULL(PageTypeID,0) <> 9)
			)

IF @FramePage = 0
BEGIN

SELECT @MenuID = ParentMenuID FROM fs_MenuPages(@MenuID,1) WHERE @FramePage = 1

IF @@ROWCOUNT > 0
	INSERT INTO @T
	SELECT PageID, PageDesc, PageURL,ParentMenuID,TabIndex FROM  fs_MenuPages(@MenuID,@FramePage)

END

INSERT INTO @Ret
SELECT * FROM @T ORDER BY TabIndex

RETURN
END


